//! Program

use crate::parser::node::Node;
use crate::{parser::node::NodeRoot, parser::statement::Statement};

#[derive(Debug)]
pub struct Program {
    node: NodeRoot,
    statements: Vec<Box<dyn Statement>>,
}

impl Program {
    pub fn get_literal(&self) -> String {
        if self.statements.len() > 0 {
            self.statements[0].cast_to_node().get_literal().to_string()
        } else {
            "".to_string()
        }
    }

    pub fn new() -> Self {
        let node = NodeRoot::new("Program".to_string(), "Program".to_string());
        Self {
            node,
            statements: Vec::default(),
        }
    }

    pub fn add_statement(&mut self, smt: Box<dyn Statement>) {
        self.statements.push(smt);
    }

    pub fn statements(&self) -> &[Box<dyn Statement>] {
        &self.statements
    }

    pub fn as_node(&self) -> &dyn Node {
        &self.node
    }
}
